export default {
  state: {
    // 如果localStorage没有存储地址，则使用空对象
    address: JSON.parse(localStorage.getItem("address"))|| null
  },
  mutations: {
    SET_ADDRESS(state, address) {
      state.address = address; // 修改地址
      // 保存地址到 localStorage
      localStorage.setItem("address", JSON.stringify(address));
    }
  },
  actions: {
    updateAddress({ commit }, address) {
      commit('SET_ADDRESS', address); // 提交mutation修改地址
    }
  },
  getters: {
    address: (state) => state.address, // 获取地址
  }
}
